
QUnit.module('creta_keybinding', function() {

	QUnit.test('clean keybinding', function(assert) {
	
		initial_values();
		first_div.innerText = "Lorem Ipsum";
		first_div.dispatchEvent(new KeyboardEvent('keydown', {
		    code: 'C',
		    key: 'C',
		    charCode: 99,
		    keyCode: 99,
		    view: window,
		    bubbles: true,
		    shiftKey: true,
		    ctrlKey: true
		}));

		assert.equal(visual_editor.get_text(), "");
		
	});
	
	QUnit.test('link keybinding', function(assert) {
	
		initial_values();
		first_div.innerText = "Lorem Ipsum";
		let selection = window.getSelection();
		let range = document.createRange();


		range.selectNodeContents(first_div);
		selection.removeAllRanges();
		selection.addRange(range);
		first_div.dispatchEvent(new KeyboardEvent('keydown', {
		    code: 'K',
		    key: 'K',
		    charCode: 75,
		    keyCode: 75,
		    view: window,
		    bubbles: true,
		    shiftKey: true,
		    ctrlKey: true
		}));

		visual_editor_div.getElementsByClassName('link_input')[0].value = "url";
		
		let accept_button = visual_editor_div.getElementsByClassName('accept_link')[0];
		accept_button.click();
		
		assert.equal(visual_editor.get_text(), 
			"<div><a href=\"https://url\">Lorem Ipsum</a></div>");
		
	});
	
	QUnit.test('table keybinding', function(assert) {
	
		initial_values();
		first_div.innerText = "Lorem Ipsum";
		
		first_div.dispatchEvent(new KeyboardEvent('keydown', {
		    code: 'T',
		    key: 'T',
		    charCode: 84,
		    keyCode: 84,
		    view: window,
		    bubbles: true,
		    shiftKey: true,
		    ctrlKey: true
		}));
		
		visual_editor_div.getElementsByClassName('w')[0].value = "2";
		visual_editor_div.getElementsByClassName('h')[0].value = "2";
		
		let accept_button = visual_editor_div.getElementsByClassName('accept_table')[0];
		accept_button.click();
		
		assert.equal(visual_editor.get_text(), 
			"<div>Lorem Ipsum</div>\n<table style=\"border: 1px solid black;\">\n    <tbody>\n        <tr>\n            <td style=\"border: 1px solid black;\"></td>\n            <td style=\"border: 1px solid black;\"></td>\n        </tr>\n        <tr>\n            <td style=\"border: 1px solid black;\"></td>\n            <td style=\"border: 1px solid black;\"></td>\n        </tr>\n    </tbody>\n</table>\n<div></div>");
		
	});
	
	QUnit.test('list keybinding', function(assert) {
	
		initial_values();
		first_div.innerText = "Lorem Ipsum";
		
		first_div.dispatchEvent(new KeyboardEvent('keydown', {
		    code: 'L',
		    key: 'L',
		    charCode: 73,
		    keyCode: 73,
		    view: window,
		    bubbles: true,
		    shiftKey: true,
		    ctrlKey: true
		}));
		
		assert.equal(visual_editor.get_text(), 
			"<div>Lorem Ipsum</div>\n<div>\n    <ul>\n        <li></li>\n    </ul>\n</div>");
		
	});
	
	QUnit.test('sublist keybinding', function(assert) {
	
		initial_values();
		first_div.innerText = "Lorem Ipsum";
		
		first_div.dispatchEvent(new KeyboardEvent('keydown', {
		    code: 'L',
		    key: 'L',
		    charCode: 52,
		    keyCode: 52,
		    view: window,
		    bubbles: true,
		    shiftKey: true,
		    ctrlKey: true
		}));
		let sel = window.getSelection();
		let range = sel.getRangeAt(0);
		range.insertNode(document.createTextNode("Item"));
		
		visual_editor.core.get_selected_node_line().dispatchEvent(new KeyboardEvent('keydown', {
		    code: '4',
		    key: '4',
		    charCode: 73,
		    keyCode: 73,
		    view: window,
		    bubbles: true,
		    ctrlKey: true
		}));
		
		assert.equal(visual_editor.get_text(), 
			"<div>Lorem Ipsum</div>\n<div>\n    <ul>\n        <li>Item<ul>\n                <li></li>\n            </ul>\n        </li>\n    </ul>\n</div>");
		
	});
	
	QUnit.test('block keybinding', function(assert) {
	
		initial_values();
		first_div.innerText = "Lorem Ipsum";
		let selection = window.getSelection();
		let range = document.createRange();


		range.selectNodeContents(first_div);
		selection.removeAllRanges();
		selection.addRange(range);
		first_div.dispatchEvent(new KeyboardEvent('keydown', {
		    code: 'B',
		    key: 'B',
		    charCode: 66,
		    keyCode: 66,
		    view: window,
		    bubbles: true,
		    shiftKey: true,
		    ctrlKey: true
		}));
		
		visual_editor_div.getElementsByClassName('block_input')[0].value = "block_class";
		
		let accept_button = visual_editor_div.getElementsByClassName('accept_block')[0];
		accept_button.click();
		
		assert.equal(visual_editor.get_text(), 
			"<div><div class=\"block_class\">Lorem Ipsum</div></div>");
		
	});
	
	QUnit.test('metatag keybinding', function(assert) {
	
		initial_values();
		first_div.innerText = "Lorem Ipsum";
		let selection = window.getSelection();
		let range = document.createRange();


		range.selectNodeContents(first_div);
		selection.removeAllRanges();
		selection.addRange(range);
		first_div.dispatchEvent(new KeyboardEvent('keydown', {
		    code: 'M',
		    key: 'M',
		    charCode: 77,
		    keyCode: 77,
		    view: window,
		    bubbles: true,
		    shiftKey: true,
		    ctrlKey: true
		}));
		
		assert.equal(visual_editor.get_text(), 
			"<div><code>Lorem Ipsum</code></div>");
		
	});
	
	QUnit.test('embed keybinding', function(assert) {
	
		initial_values();
		first_div.innerText = "Lorem Ipsum";
		let selection = window.getSelection();
		let range = document.createRange();

		range.selectNodeContents(first_div);
		selection.removeAllRanges();
		selection.addRange(range);
		first_div.dispatchEvent(new KeyboardEvent('keydown', {
		    code: 'E',
		    key: 'E',
		    charCode: 69,
		    keyCode: 69,
		    view: window,
		    bubbles: true,
		    shiftKey: true,
		    ctrlKey: true
		}));
		
		assert.equal(visual_editor.get_text(), 
			"<div class=\"embed\">Lorem Ipsum</div>");
		
	});

  });

  

